package linkExcel.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class ReadTxtFile {
    public static String readTxtFile(String filePath) {
        StringBuilder result = new StringBuilder();
        try {
            File file = new File(filePath);
            if (file.isFile() && file.exists()) {
                FileInputStream fis = new FileInputStream(file);
                InputStreamReader isr = new InputStreamReader(fis);
                BufferedReader br = new BufferedReader(isr);
                String line;
                while ((line = br.readLine()) != null) {
                    result.append(line).append("\n");
                }
                br.close();
                isr.close();
                fis.close();
            } else {
                System.out.println("文件不存在！");
            }
        } catch (Exception e) {
            System.out.println("读取文件内容出错！");
            e.printStackTrace();
        }
        return result.toString();
    }
}
